﻿using DreamCMS.Entity.Common;
using DreamCMS.WebCore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DreamCMS.Entity
{
    public class CategoryInfo:IComparable<CategoryInfo>
    {
        public int CompareTo(CategoryInfo other)
        {
            if(this.diplayorder!=other.diplayorder)
            {
                return this.diplayorder.CompareTo(other.diplayorder);
            }
            return this.catId.CompareTo(other.catId);
        }

        private long catId;
        /// <summary>
        /// 类别ID
        /// </summary>
        public long CatId
        {
            get { return catId; }
            set { catId = value; }
        }

        private CatType type;
        /// <summary>
        /// 栏目类别
        /// </summary>
        public CatType Type
        {
            get { return type; }
            set { type = value; }
        }

        private string name;
        /// <summary>
        /// 栏目名称
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private string slug;
        /// <summary>
        /// 栏目别名
        /// </summary>
        public string Slug
        {
            get { return slug; }
            set { slug = value; }
        }
        private string description;
        /// <summary>
        /// 栏目描述
        /// </summary>
        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        private long diplayorder;
        /// <summary>
        /// 栏目排序
        /// </summary>
        public long Diplayorder
        {
            get { return diplayorder; }
            set { diplayorder = value; }
        }
        private long postCount=0;
        /// <summary>
        /// 栏目文章数
        /// </summary>
        public long PostCount
        {
            get { return postCount; }
            set { postCount = value; }
        }

        private DateTime createDate=DateTime.Now;
        /// <summary>
        /// 栏目创建时间
        /// </summary>
        public DateTime CreateDate
        {
            get { return createDate; }
            set { createDate = value; }
        }
        /// <summary>
        /// 栏目的URL地址
        /// </summary>
        public string Url
        {
            get
            {
                string url = string.Empty;
                if (!string.IsNullOrEmpty(slug))
                {
                    url = ConfigHelper.SiteRootPath + "category.aspx?cat=" + slug;
                    return url;
                }
                url =ConfigHelper.SiteRootPath + "category.aspx?cat=" + catId;
                return url;

            }
        }
        /// <summary>
        /// 栏目的html链接地址
        /// </summary>
        public string Link
        {
            get
            {
                string link = "<a href=\"{0}\" title=\"{1}\">{2}</a>";
                return string.Format(link, this.Url, this.name, this.name);
            }
        }

        public string RssUrl
        {
            get
            {
                string url = "{0}rss.aspx?type=cat&id={1}";
                return string.Format(url, ConfigHelper.SiteRootPath, this.catId);
            }
        }

        public string RssLink
        {
            get
            {
                string rssLink = "<a href=\"{0}\" title=\"{1}\">{1}</a>";
                return string.Format(rssLink, RequestHelper.SiteUrl, this.RssUrl);
            }
        }
    }
}
